package com.jr.service.impl;

import com.jr.entry.BookInfo;
import com.jr.entry.Users;
import com.jr.mapper.UsersMapper;
import com.jr.service.UsersService;

import com.jr.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UsersServiceImpl implements UsersService {
    @Autowired
    private UsersMapper usersMapper;
    @Override
    public boolean login(Users user) {
        return usersMapper.selectUserByInfo(user).size()>0?true:false;
    }


    @Override
    public PageBean<BookInfo> selectAllBook(int currentPage, int pageSize) {
        PageBean<BookInfo> pageBean=new PageBean<>();
        int totalCount = usersMapper.selectAll().size();
        pageBean.setTotalCount(totalCount);
        pageBean.setSize(pageSize);
        pageBean.setIndex(currentPage);
        List<BookInfo> list = usersMapper.selectAllBook(pageSize,(currentPage-1)*pageSize);
        pageBean.setList(list);
        return pageBean;
    }

    @Override
    public List<BookInfo> selectBookByInfo(BookInfo bookInfo) {
        return usersMapper.selectBookByInfo(bookInfo);
    }

    @Override
    public BookInfo selectBookByBookCode(BookInfo bookInfo) {
        return usersMapper.selectBookByBookCode(bookInfo);
    }

    @Override
    public boolean updateBook(BookInfo bookInfo) {
        return usersMapper.updateBook(bookInfo)==1?true:false;
    }

    @Override
    public boolean deleteBook(String book_code) {
        return usersMapper.deleteBook(book_code)==1?true:false;
    }

    @Override
    public boolean addBook(BookInfo bookInfo) {
        return usersMapper.addBook(bookInfo)==1?true:false;
    }
}
